import api from "./index";
import type { ApiConfig, ApiQuery, ApiResponse } from "@/types/api";

// 获取API列表
export const getApiList = async (params: {
  keyword?: string;
  page?: number;
  pageSize?: number;
}) => {
  const response = await api.get("/api/list", { params });
  return response.data;
};

// 创建API
export const createApi = async (data: Omit<ApiConfig, "id">) => {
  const response = await api.post("/api/create", data);
  return response.data;
};

// 更新API
export const updateApi = async (id: number, data: Partial<ApiConfig>) => {
  const response = await api.put(`/api/update?id=${id}`, data);
  return response.data;
};

// 删除API
export const deleteApi = async (id: number) => {
  const response = await api.delete(`/api/delete?id=${id}`);
  return response.data;
};

// 测试API
export const testApi = async (id: number, params?: any) => {
  const response = await api.post(`/api/test?id=${id}`, params);
  return response.data;
};
